﻿@model IEnumerable<FCNS.ERP.Models.DefineClass.DefineBookDinner>

@{
    ViewBag.Title = "订餐";
    Layout = "~/Views/Shared/_Layout.cshtml";;
}

<h2>@ViewBag.Title</h2>
 <script type="text/javascript">
     $(document).ready(function () {
         $(":button").click(function () {
             var bId=$(this).attr("data-Id");
             var d1Id = $(this).parent().parent().find("#DinnerTypeId option:selected").val(); 
             var d2Id = $(this).attr("data-planId");
             
             var btn = $(this);
             $.post("/BookDinner/BookDinnerInsert",
                 {
                     id: bId,
                     typeId: d1Id,
                     planId: d2Id
                 },
                 function (data, status) { 
                     if (status == "success")
                     {
                         if (data == "-1")
                         {
                             btn.prop("value", '预定');
                             btn.parent().prev().text('空闲');
                         }
                         else
                         {
                             btn.prop("value", '取消');
                             btn.parent().prev().text('订餐');
                         }
                         btn.attr("data-Id", data);
                     }
                     else
                     {
                         alert("操作失败");
                     }
             });
         });
    });
    </script>
@{
    var typeObj = ViewData["DinnerTypeList"] as SelectList;
 }
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Date)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.BookDinnerType)
        </th> 
        <th>@Html.DisplayNameFor(model => model.DinnerTypeId)</th>
        <th>
            @Html.DisplayNameFor(model => model.BookDinnerStatus)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Date)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BookDinnerType)
        </td>
        <td>
            <select class="form-control" id="DinnerTypeId" name="DinnerTypeId">
                @foreach (var v in typeObj)
                {
                    if (v.Value == item.DinnerTypeId.ToString())
                    {
                        <option selected="selected" value=@v.Value>@v.Text</option>
                    }
                    else
                    {
                        <option value=@v.Value>@v.Text</option>
                    }
                } 
            </select>
        </td>
      
        <td>
            @Html.DisplayFor(modelItem => item.BookDinnerStatus)
        </td>
        <td>
            @{
                if (item.Date.ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
                {
                    continue;
                }
                string str = (item.DinnerTypeId != -1 ? "取消" : "预定");
            }

                <input type="button" value="@str" class="btn btn-default" data-Id="@item.Id" data-planId="@item.DinnerPlanId"/>
        </td>
    </tr>
}

</table>
